package com.yy.jhl.ui.manager.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yy.common.base.BaseAdapter;
import com.yy.common.commonwidget.OnNoDoubleClickListener;
import com.yy.jhl.R;
import com.yy.jhl.bean.MessageListInfo.DataBean;
import com.yy.jhl.bean.MessageListInfo;
import com.yy.jhl.ui.manager.activity.LogisticsManagerActivity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


/**
 * Created by Ellis.Li on 2017/6/15.
 */

public class MessageAdapter extends BaseAdapter {
    private List<MessageListInfo.DataBean> modelList;
    public MessageAdapter(Context context) {
        super(context);
        modelList = new ArrayList<>();
    }
    @Override
    public void removeItem(int position) {
        super.removeItem(position);
        modelList.remove(position);
        notifyDataSetChanged();
    }
    @Override
    public void clearData() {
        super.clearData();
        modelList.clear();
        notifyDataSetChanged();
    }
    public void addData(List<MessageListInfo.DataBean> monomerModels) {
        if (monomerModels != null && monomerModels.size() > 0){
//            Collections.reverse(monomerModels);
            modelList.addAll(monomerModels);
            notifyDataSetChanged();
        }
    }

    public void addAllData(List<MessageListInfo.DataBean> monomerModels) {
        clearData();
        modelList.addAll(monomerModels);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return modelList.size();
    }

    @Override
    public Object getItem(int i) {
        return modelList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder storeHolder;
        if(view == null){
            storeHolder = new Holder();
            view = layoutInflater.inflate(R.layout.item_messgae,null);
            storeHolder.initView(view);
            view.setTag(storeHolder);
        }else{
            storeHolder = (Holder)view.getTag();
        }
        final MessageListInfo.DataBean itemModel = modelList.get(i);
        storeHolder.message_date_text.setText(itemModel.getCreate_time());
        storeHolder.message_content_text.setText(itemModel.getMessage());
        return view;
    }
    /**
     *
     */
    class Holder{
        private TextView message_date_text;
        private TextView message_content_text;
        void initView(View view) {
            message_date_text = (TextView) view.findViewById(R.id.message_date_text);
            message_content_text = (TextView) view.findViewById(R.id.message_content_text);
        }

    }
}
